home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14240 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to detect EOF?/filepointer problem.
  5. Date: 12 Apr 1996 11:35:11 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4km7ovINN7r@keats.ugrad.cs.ubc.ca>
  8. References: <316F8932.2BAF@www.partio.fi>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <316F8932.2BAF@www.partio.fi>,
  12. R.K.Brand <ralph@www.partio.fi> wrote:
  13.  >Sorry to bother you, but I have a problem 
  14.  >while scanning through a file too see whether 
  15.  >or not a certain word occurs.
  16.  >When I run out of file, fscanf() keeps 
  17.  >returning the last line, instead of some NULL 
  18.  >value I would find logical (but who am I?).
  19.  
  20. How can fscanf() ``return a line'', when its return type is int?
  21.  
  22.  >How can I test for the end of the file?
  23.  
  24. Not directly.  fscanf() returns the number of fields it was able to retrieve.
  25. For example, if you use a conversion string "%s", it will return 1 if it was
  26. able to retrieve a whitespace-delimited string, or zero otherwise. I'd take the
  27. zero as a cue that there aren't any more words available in the input.
  28.  
  29.  >The second problem is how to manipulate a 
  30.  >pointer of type "FILE"..so, a filepointer.
  31.  >At a certain point I want to skip 11 chars back 
  32.  >in the file and start writing.
  33.  
  34. This is tricky in conjunction with a scanning function like fscanf(). You have
  35. to understand what it does with the whitespace after the word.
  36.  
  37.  
  38.  >string-=11; gives me an error and after
  39.  >string--; fprintf(string,"foo"); does not do 
  40.  >anything anymore.
  41.  
  42. The FILE * is not a pointer to the characters of the file! You may not
  43. alter the value of this pointer!
  44.  
  45. The FILE * pointer points to a structure which maintains a whole ton of
  46. information about an open stream. To advance or retreat the file pointer, you
  47. must use the fseek() function.
  48.  
  49.  >I you respond to this one, please do also mail 
  50.  >me a copy.
  51.  
  52. Sigh.
  53. -- 
  54.  
  55.